package com.szeldon.declatest.declaration.scenario;

import java.util.ArrayList;
import java.util.List;

import com.szeldon.declatest.declaration.scenario.parts.ScenarioPartDeclaration;
import com.szeldon.declatest.declaration.scenario.parts.ScenarioPartsHelper;
import com.szeldon.utils.ValuesUtils;

/**
 * Class holding declaration of scenario. Scenario is just a tree of conditions and steps.
 * 
 * @author szeldon
 * 
 */
public class ScenarioDeclaration {

    /** List of parts of scenario. */
    private List<ScenarioPartDeclaration> partsList = new ArrayList<ScenarioPartDeclaration>();
    /** Scenario's ID. */
    private String scenarioId;
    /** Scenario's description. */
    private String scenarioDescription;

    /**
     * Creates declaration of scenario.
     * 
     * @param scenarioId
     * @param scenarioDescription
     */
    public ScenarioDeclaration(String scenarioId, String scenarioDescription) {
        this.scenarioId = ValuesUtils.checkNamedValueForNull("id", scenarioId);
        this.scenarioDescription = ValuesUtils.checkNamedValueForNull("description", scenarioDescription);
    }

    /**
     * Adds declaration of given scenario part. If some parts were added before, this part will be added after them.
     * 
     * @param scenarioPart
     * @throws UnsupportedOperationException
     *             Thrown when given scenario part can't be added in current context (e.g. "If" can't be added after
     *             "If").
     */
    public void addScenarioPart(ScenarioPartDeclaration scenarioPart) throws UnsupportedOperationException {
        ScenarioPartsHelper.tryAddingPartAfter(scenarioPart, partsList);
    }

    /**
     * Returns list of parts of this scenario.
     * 
     * @return
     */
    public List<ScenarioPartDeclaration> getPartsList() {
        return partsList;
    }

    public String getId() {
        return scenarioId;
    }

}
